//
//  UIWindow+Extension.m
//  SinaWeibo
//
//  Created by Apple on 16/8/13.
//  Copyright © 2016年 Apple. All rights reserved.
//

#import "UIWindow+Extension.h"
#import "WelcomeViewController.h"
#import "WelcomeBackViewController.h"

@implementation UIWindow (Extension)

-(void)chooseRootViewController{
    
    // 3.判断应该显示新特性还是欢迎界面
    // 3.1获取当前软件版本号
#warning 注意, 取出的版本号一定更要用字符串保存, 不要用浮点数 1.1.1
    NSString *currentVersion = [NSBundle mainBundle].infoDictionary[@"CFBundleShortVersionString"];
    
    // 3.2获取沙盒中存储的软件版本号
    NSUserDefaults *usetDefault = [NSUserDefaults standardUserDefaults];
    NSString *versionFromSandbox = [usetDefault objectForKey:@"CFBundleShortVersionString"];
    
    // 3.3比较两个软件版本号
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    if ([currentVersion compare:versionFromSandbox] == NSOrderedDescending) {
        //如果是新版本
        WelcomeViewController *welcomVC =  [[WelcomeViewController alloc]init];
        window.rootViewController = welcomVC;
        
        //储存当前版本号
        [usetDefault setObject:currentVersion forKey:@"CFBundleShortVersionString"];
        [usetDefault synchronize];
        
    }else{
        
        WelcomeBackViewController *welcomeBackVC = [[WelcomeBackViewController alloc]init];
        window.rootViewController = welcomeBackVC;
        
    }
}

@end
